package leetcode.median;

import leetcode.base.TreeNode;

/**
 * ClassName: $98_IsValidBST
 * Description:
 * date: 2021-12-08 9:47
 *
 * @author liyifan
 */
public class $98_IsValidBST {
    public boolean isValidBST(TreeNode root) {
        return isValidBST(root, null, null);
    }

    public boolean isValidBST(TreeNode root, TreeNode max, TreeNode min) {
        if (root == null)
            return true;
        if (min != null && root.val <= min.val)
            return false;
        if (max != null && root.val >= max.val)
            return false;
        return isValidBST(root.left, root, min) && isValidBST(root.right, max, root);
    }
}
